#ifndef TRACKDATASERVER_HPP
#define TRACKDATASERVER_HPP

#include "hiout.pb.h"
#include "ConcurrentQueue.hpp"

#include <boost/asio.hpp>

#include <cv.h>

class AbstractTrackDataServer {
public:
	virtual void run()=0;
	virtual void putTrackData( hi::TrackData& trackData )=0;
	virtual void putTrackData( bool active, int x, int y )=0;
	virtual void putTrackData( bool active, int x, int y, bool secondActive, int secondX, int secondY )=0;
	const static int portnum = 24312; //randomly chosen
	
	~AbstractTrackDataServer() {};
};

class SynTCPTrackDataServer : public AbstractTrackDataServer {
public:
	virtual void run();
	virtual void putTrackData( hi::TrackData& trackData );
	virtual void putTrackData( bool active, int x, int y );  
	virtual void putTrackData( bool active, int x, int y, bool secondActive, int secondX, int secondY ); 
	
	SynTCPTrackDataServer(boost::function<void()> startTrackerCallback);
	SynTCPTrackDataServer(boost::function<void()> startTrackerCallback, boost::function<void()> completionCallback );
	~SynTCPTrackDataServer();
protected:
	hi::ConcurrentQueue< hi::TrackData > trackDataQueue;
	boost::function<void()> startTrackerCallback;
	boost::function<void()> completionCallback;
	
	void writeTrackDataToArray( hi::TrackData& trackData, char* dataBuf, int dataBufSize );
	void startTrackerThread(boost::shared_ptr<boost::asio::ip::tcp::socket> scktPtr);
	
	void runInner(boost::shared_ptr<boost::asio::ip::tcp::socket> scktPtr);
	
	bool hasCompletionCallback;
};

#endif